package Gui.Dialogs;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import Cards.Card;
import Cards.MailCardBill;
import Gui.GameFrame;
import Main.Defines;

public class MailCardBillDialog extends JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5576051974883456418L;

	// JLabel Title;
	// JLabel Cost;
	// JLabel Value;
	JPanel jp;

	public MailCardBillDialog(JFrame parent, final MailCardBill DrawnCard) {
		//super(parent, "Mail Card Bill Dialog", true);
		setModalityType(getModalityType().APPLICATION_MODAL);
		jp = new JPanel();
		jp.setBorder(Defines.getEmptyBorderConstraints());
		jp.setLayout(new GridLayout(0, 1, 0, 10));
		

		// Draws the info for DrawnCard
		// Title = new JLabel("You Recieved A Mail Card Bill ");
		JLabel textLabel = new JLabel();
		String text = "<html>You Recieved A Mail Card Bill <br>";
		text += DrawnCard.toString();
		text += "<br>It's Worth: " + DrawnCard.getValue();
		// Cost = new JLabel("It Costs: " + DrawnCard.getCost());
		// Cost = new JLabel(DrawnCard.toString());
		// Value = new JLabel("It's Worth: " + DrawnCard.getValue());

		JButton ok = new JButton("ok");
		ok.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();

			}
		});

		jp.add(textLabel, BorderLayout.NORTH);
		// jp.add(Cost);
		// add(Value);
		jp.add(ok, BorderLayout.SOUTH);
		add(jp);
		pack();
		setLocationRelativeTo(parent);
		setVisible(true);

		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}

	public MailCardBillDialog(GameFrame parent, Vector<Card> billPile) {
		//super(parent, "Mail Card Bill Dialog", true);
		setModalityType(getModalityType().APPLICATION_MODAL);
		jp = new JPanel();
		jp.setBorder(Defines.getEmptyBorderConstraints());
		// setLayout(new GridLayout(0, 1, 0, 10));
		jp.setLayout(new BorderLayout(0, Defines.VERTICAL_PADDING));
		

		// Create the 'ok' button.
		JButton ok = new JButton("ok");
		ok.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();

			}
		});

		// Draws the info for DrawnCard

		JPanel billsContainer = new JPanel(new GridLayout(0,
				Defines.SINGLE_ROW_COLUMN_MODIFIER));
		String text = "<html>You Recieved Mail Card Bill(s) <br><br>";
		billsContainer.add(new JLabel(text));
		for (Card c : billPile) {
			JPanel row = new JPanel(new BorderLayout());
			JLabel billLeftText = new JLabel(((MailCardBill) c).getName(),
					SwingConstants.LEFT);
			JLabel billRightText = new JLabel(String.format("" +
					"  You owe $%d",
					((MailCardBill) c).getCost()), SwingConstants.RIGHT);
			row.add(billLeftText, BorderLayout.WEST);
			row.add(billRightText, BorderLayout.EAST);
			billsContainer.add(row);
		}

		jp.add(billsContainer, BorderLayout.NORTH);
		jp.add(ok, BorderLayout.SOUTH);

		add(jp);
		pack();

		if (getTitle() != null) {
			FontMetrics fm = getFontMetrics(getFont());
			int width = fm.stringWidth(getTitle()) + Defines.ICON_WIDTH;
			width = (int) Math.max(width * 1.2, getPreferredSize().getWidth());
			setSize(new Dimension(width, getHeight()));
		}
		setLocationRelativeTo(parent);
		setVisible(true);

		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}

}
